﻿using System;
using System.Xml.Serialization;

namespace HobSoft.SoccerBet2014.Client.ViewModels
{
    using dm=Domain.Models;

    [Serializable]
    [XmlRoot("order")]
    public class BmOrder : ViewModelBase
    {
        private byte _bmID;
        [XmlAttribute("bm-id")]
        public byte BmID
        {
            get { return _bmID; }
            set { PropertyValueChange(ref _bmID, value, "BmID"); }
        }

        private string _recId;
        [XmlAttribute("rec-id")]
        public string RecID
        {
            get { return _recId; }
            set { PropertyValueChange(ref _recId, value, "RecID"); }
        }

        private string _league;
        [XmlAttribute("league")]
        public string League
        {
            get { return _league; }
            set { PropertyValueChange(ref _league, value, "League"); }
        }

        private string _homeTeam;
        [XmlAttribute("home-team")]
        public string HomeTeam
        {
            get { return _homeTeam; }
            set { PropertyValueChange(ref _homeTeam, value, "HomeTeam"); }
        }

        private string _awayTeam;
        [XmlAttribute("away-team")]
        public string AwayTeam
        {
            get { return _awayTeam; }
            set { PropertyValueChange(ref _awayTeam, value, "AwayTeam"); }
        }

        private byte _homeScore;
        [XmlAttribute("home-score")]
        public byte HomeScore
        {
            get { return _homeScore; }
            set { PropertyValueChange(ref _homeScore, value, "HomeScore"); }
        }

        private byte _awayScore;
        [XmlAttribute("away-score")]
        public byte AwayScore
        {
            get { return _awayScore; }
            set { PropertyValueChange(ref _awayScore, value, "AwayScore"); }
        }

        private dm.MarketType _type;
        [XmlAttribute("type")]
        public dm.MarketType Type
        {
            get { return _type; }
            set
            {
                PropertyValueChange(ref _type, value, "Type");
                RaisePropertyChanged("BetToDisplay");
            }
        }

        private BetItem _betTo;
        [XmlAttribute("bet-to")]
        public BetItem BetTo
        {
            get { return _betTo; }
            set
            {
                PropertyValueChange(ref _betTo, value, "BetTo");
                RaisePropertyChanged("BetToDisplay");
            }
        }

        [XmlIgnore]
        public string BetToDisplay
        {
            get
            {
                string result = string.Empty;
                switch (BetTo)
                {
                    case BetItem.Tie:
                        result = "和";
                        break;
                    case BetItem.HomeOrOver:
                        if (Type == dm.MarketType.M1X2)
                        {
                            result = "主胜";
                        }
                        else if (Type == dm.MarketType.MHDP)
                        {
                            result = HomeTeam;
                        }
                        else if (Type == dm.MarketType.MOU)
                        {
                            result = "大";
                        }
                        break;
                    case BetItem.AwayOrUnder:
                        if (Type == dm.MarketType.M1X2)
                        {
                            result = "客队";
                        }
                        else if (Type == dm.MarketType.MHDP)
                        {
                            result = AwayTeam;
                        }
                        else if (Type == dm.MarketType.MOU)
                        {
                            result = "小";
                        }
                        break;
                    default:
                        break;
                }
                return result;
            }
        }

        private decimal _oddsValue;
        [XmlAttribute("odds-value")]
        public decimal OddsValue
        {
            get { return _oddsValue; }
            set { PropertyValueChange(ref _oddsValue, value, "OddsValue"); }
        }

        private decimal _handicap;
        [XmlAttribute("handicap")]
        public decimal Handicap
        {
            get { return _handicap; }
            set
            {
                PropertyValueChange(ref _handicap, value, "Handicap");
                RaisePropertyChanged("HandicapDisplay");
                if (Type == dm.MarketType.M1X2)
                    HandicapDisplay = "";
                else
                    HandicapDisplay = Handicap.ToString();
            }
        }

        private string _handicapDisplay;
        [XmlIgnore]
        public string HandicapDisplay
        {
            get { return _handicapDisplay; }
            set { PropertyValueChange(ref _handicapDisplay, value, "HandicapDisplay"); }
        }

        private string _betAccount;
        [XmlAttribute("account")]
        public string BetAccount
        {
            get { return _betAccount; }
            set { PropertyValueChange(ref _betAccount, value, "BetAccount"); }
        }

        private decimal _betMoney;
        [XmlAttribute("bet-money")]
        public decimal BetMoney
        {
            get { return _betMoney; }
            set { PropertyValueChange(ref _betMoney, value, "BetMoney"); }
        }

        private DateTime? _betTime;
        [XmlAttribute("bet-time")]
        public DateTime? BetTime
        {
            get { return _betTime; }
            set { PropertyValueChange(ref _betTime, value, "BetTime"); }
        }

        private string _rawResult;
        [XmlAttribute("raw-result")]
        public string RawResult
        {
            get { return _rawResult; }
            set { PropertyValueChange(ref _rawResult, value, "RawResult"); }
        }
    }
}
